<template>
    <div>
        <div class="list">
            <articleItem 
                v-for="(item, index) in list" 
                @click="toUserList(item)"
                :item="item" :key="index" type="team"></articleItem>
        </div>
        <pub-list-end :loading="scroll.loading" :max="scroll.max" :noData="scroll.noData"></pub-list-end>
        
    </div>
</template>

<script>
import articleItem from '@/components/pages/article-item.vue'
import { getTeamShareHisByUser, getTeamShareHisByDynamic }  from '@/request/team'
export default {
    components: {
        articleItem,
    },
    data() {
        return {
            viewerId: '',
            list: [],
            scroll: {
                page: 1,
                size: 30,
                loading: false,
                max: false,
                noData: false,
            },
        }
    },
    onLoad({ viewerId }) {
        this.viewerId = viewerId
        this.onRefresh()
    },
    methods: {
        getList(complete) {
            getTeamShareHisByUser({
                viewerId: this.viewerId,
                pageIndex: this.scroll.page,
                pageSize: this.scroll.size,
            }, {complete}).then(res => {
                this.list = res.data.list
                this.scroll.max = this.list.length >= res.data.total
                this.scroll.noData = res.data.total == 0

            })
        },
        // 重头第一页刷新列表
        onRefresh() {
            this.scroll.loading = true
            this.scroll.max = false
            this.scroll.noData = false
            this.scroll.page = 1
            this.shareUserList = []
            this.getList(() => {
                this.scroll.loading = false;
                uni.stopPullDownRefresh()
            })
        },
        // 滚动到底部加载
        onInfinite() {
            if(this.scroll.loading || this.scroll.max) return
            this.scroll.loading = true
            this.scroll.page += 1
            this.getList(() => {
                this.scroll.loading = false
            })
        },
        toUserList(item) {
            this.$navigate.to('/pages/team/userList?dynamicId=' + item.dynamicId)
        }
    }
}
</script>

<style lang="less" scoped>
.list{
    background: #fff;
    padding: 20rpx 30rpx;
}

</style>